#include "StdAfx.h"
#include "AccountInfoMgr.h"
#include "Buddylist.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CAccountInfoMgr *CAccountInfoMgr::s_Intance = NULL;

CAccountInfoMgr::CAccountInfoMgr(void)
:m_pBuddylist(NULL)
{
	memset(&m_stAccount,0,sizeof(AccountData));
}

CAccountInfoMgr::~CAccountInfoMgr(void)
{
	if (m_pBuddylist)
	{
		delete m_pBuddylist;
		m_pBuddylist = NULL;
	}
}


CAccountInfoMgr *CAccountInfoMgr::GetInstance()
{
	if (!s_Intance)
	{
		s_Intance = new CAccountInfoMgr;

		_ASSERTE(s_Intance);
	}

	return s_Intance;

}

void CAccountInfoMgr::ReleaseInstance()
{
	if (s_Intance)
	{
		delete s_Intance;
		s_Intance = NULL;
	}
}

void CAccountInfoMgr::SetAccountName(TCHAR *szAccount)
{
	if (!szAccount)
	{
		_ASSERTE(FALSE);

		return;
	}

	_tcsncpy_s(m_stAccount.szAccoutName,MAX_PASSWORD_LEN,szAccount,MAX_PASSWORD_LEN - 1);

	return;	
}
void CAccountInfoMgr::SetPassword(TCHAR *szPassword)
{
	if (!szPassword)
	{
		_ASSERTE(FALSE);

		return;
	}

	_tcsncpy(m_stAccount.szPassword,szPassword,MAX_PASSWORD_LEN - 1);
}

void CAccountInfoMgr::SetNickName(TCHAR *szNickName)
{
	if (!szNickName)
	{
		_ASSERTE(FALSE);

		return;
	}

	_tcsncpy(m_stAccount.szNick,szNickName,MAX_NICKNAME_LEN - 1);
}

CString CAccountInfoMgr::GetAccountName()
{
	return (CString)m_stAccount.szAccoutName;
}

CString CAccountInfoMgr::GetNickName()
{
	return (CString)m_stAccount.szNick;
}


HRESULT CAccountInfoMgr::GetBuddylist(IBuddylist **ppBuddylist)
{
	if (!m_pBuddylist)
	{
		m_pBuddylist = new CBuddylist;
		_ASSERTE(m_pBuddylist);
	}

	*ppBuddylist = m_pBuddylist;

	return S_OK;
}